<?php

class Auth extends CI_Controller{
	function login($username ="", $password=""){
		$username= $this->input->post('username',TRUE);
		$password=$this->input->post('password',TRUE);
		$query= "select * from user where `username`='$username' and `password`='$password'";
		$r= $this->db->query($query);
		
		if ($r->num_rows()==1){
			foreach($r->result_array() as $user){
			
			$this->session->set_userdata('userid',$user['id']);
			$this->session->set_userdata('login',TRUE);
			$url=base_url().'dashboard';
			redirect($url);
			}
		}
		else{
		$url=base_url().'login';
			redirect($url);
		}
		
	}
	function logout(){
		$this->session->set_userdata('userid','');
		$this->session->set_userdata('login',FALSE);
		redirect($base_url);
	}
	
}
